#include "festival.h"
#include <stdio.h>
#include <string.h>
#include "lunar.h"

// 公历节日表
typedef struct { int month, day; const char* name; } SolarFestival;
static SolarFestival solarFestivals[] = {
    {1, 1, "元旦"},
    {2, 2, "世界湿地日"},
    {2, 14, "情人节"},
    {3, 5, "学雷锋纪念日"},
    {3, 8, "妇女节"},
    {3, 12, "植树节"},
    {3, 15, "消费者权益日"},
    {4, 1, "愚人节"},
    {4, 4, "清明节"}, // 实际为4月4或5日
    {5, 1, "劳动节"},
    {5, 4, "青年节"},
    {5, 12, "护士节"},
    {6, 1, "儿童节"},
    {7, 1, "建党节"},
    {8, 1, "建军节"},
    {9, 3, "抗战胜利纪念日"},
    {9, 10, "教师节"},
    {10, 1, "国庆节"},
    {10, 24, "联合国日"},
    {11, 11, "光棍节"},
    {12, 1, "世界艾滋病日"},
    {12, 24, "平安夜"},
    {12, 25, "圣诞节"},
    {0, 0, NULL}
};

// 农历节日表
typedef struct { int month, day; const char* name; } LunarFestival;
static LunarFestival lunarFestivals[] = {
    {12, 8, "腊八节"},
    {12, 23, "北方小年"},
    {12, 24, "南方小年"},
    {1, 1, "春节"},
    {1, 15, "元宵节"},
    {2, 2, "龙抬头"},
    {5, 5, "端午节"},
    {7, 7, "七夕节"},
    {7, 15, "中元节"},
    {8, 15, "中秋节"},
    {9, 9, "重阳节"},
    {10, 1, "寒衣节"},// 有些年份腊月只有29天，除夕应为腊月最后一天
    {0, 0, NULL}
};

// 查询公历节日
const char* GetSolarFestival(int month, int day) {
    for (int i = 0; solarFestivals[i].name; ++i) {
        if (solarFestivals[i].month == month && solarFestivals[i].day == day)
            return solarFestivals[i].name;
    }
    return "";
}

// 查询农历节日
const char* GetLunarFestival(int month, int day) {
    for (int i = 0; lunarFestivals[i].name; ++i) {
        if (lunarFestivals[i].month == month && lunarFestivals[i].day == day)
            return lunarFestivals[i].name;
    }
    return "";
}

// 显示某月所有公历节日
void ShowSolarFestivalsOfMonth(int month) {
    printf("公历%d月的节日：\n", month);
    int found = 0;
    for (int i = 0; solarFestivals[i].name; ++i) {
        if (solarFestivals[i].month == month) {
            printf("%d月%d日: %s\n", month, solarFestivals[i].day, solarFestivals[i].name);
            found = 1;
        }
    }
    if (!found) printf("本月无常见节日。\n");
}

// 显示所有农历节日
void ShowAllLunarFestivals() {
    printf("农历常见节日：\n");
    for (int i = 0; lunarFestivals[i].name; ++i) {
        char lmonth[16] = "", lday[16] = "";
        LunarMonthToChinese(lunarFestivals[i].month, 0, lmonth, sizeof(lmonth));
        LunarDayToChinese(lunarFestivals[i].day, lday, sizeof(lday));
        printf("%s%s: %s\n", lmonth, lday, lunarFestivals[i].name);
    }
    char lmonth[16] = "", lday[16] = "";
    LunarMonthToChinese(12, 0, lmonth, sizeof(lmonth));
    snprintf(lday, sizeof(lday), "最后一天");
    printf("%s%s: 除夕\n", lmonth, lday);
} 
